package logic

import (
	"context"
	"product_zc/models/mysql"

	"product_zc/productRpc/internal/svc"
	"product_zc/productRpc/productRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClassAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewClassAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClassAddLogic {
	return &ClassAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ClassAddLogic) ClassAdd(in *productRpc.ClassAddRequest) (*productRpc.ClassAddResponse, error) {
	// todo: add your logic here and delete this line

	class := mysql.Class{
		UserId:    in.UserId,
		ClassName: in.ClassName,
	}

	mysql.DB.Create(&class)

	return &productRpc.ClassAddResponse{
		Id: int64(class.ID),
	}, nil
}
